<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>30.面向对象的多态</title>
</head>

<body>
</body>
<script>
  //根据多种不同的形态产生不同的结果，下而会根据不同形态的对象得到了不同的结果。

  function User () { }
  User.prototype.show = function () {
    console.log(this.description());
  };

  function Admin () { }
  Admin.prototype = Object.create(User.prototype);
  Admin.prototype.description = function () {
    return "管理员在此";
  };

  function Member () { }
  Member.prototype = Object.create(User.prototype);
  Member.prototype.description = function () {
    return "我是会员";
  };

  function Enterprise () { }
  Enterprise.prototype = Object.create(User.prototype);
  Enterprise.prototype.description = function () {
    return "企业帐户";
  };

  for (const obj of [new Admin(), new Member(), new Enterprise()]) {
    obj.show();
  }
</script>

</html>